<include file=".:Common:header" />
<script language="javascript">
$(function(){
	$('#datagrid').datagrid({
		toolbar:[{
			id:'btnadd',
			text:'新增指标',
			iconCls:'icon-add',
		    handler:function(){
			  $('#add').window('open');
			  $('#ff').show();
			  $('#ff').form('clear');
			  $('#ff').appendTo('#aa');
			}
		},'-',
		{
			text:'编辑指标',
			iconCls:'icon-edit',
			handler:function(){
				getSelect();
			}
		},'-',{
			text:'删除指标',
			iconCls:'icon-remove',
			handler:function(){
				var row = $('#datagrid').datagrid('getSelected');
				if (row){
					$.messager.confirm('提示', '确定删除吗？', function(r){
					if (r){
						ajaxPost("{:U('Indicator/remove')}", {'indicator_id': row.indicator_id}, function(d){
						var d = runJson(d);
							if(d.status == 0){
								alertText(d.info, 'error');
							}else{
								$('#datagrid').datagrid('reload');
							}
						});
					}else return false;
					});	
				}
			}
		},'-',{
			id:'btn-select',
			text:'查询',
			iconCls:'icon-search',
			handler:function(){
			 $('#query').window('open');
			}
		}]
	});

		$('#datagrid').datagrid({
		url : '{:U("Service/Indicator/lst")}&d='+Math.random(),
		title: '测试指标列表',
		width: '100%',
		height:'495',
		singleSelect :true,
		pagination : true,
		striped:true,
		idField: 'indicator_id',
		columns: [[
			{title:'indicator_id', field:'indicator_id', width:50, sortable:true, checkbox:true},
			{title:'指标名称', field:'name', width:100, sortable: true,rowspan:3},
			{title:'所属业务', field:'service_name', width:100, sortable: true,align:'center'},
			{title:'指标类型', field:'type_name', width:100, sortable: true,align:'center'},
			{title:'指标说明', field:'info', width:150, sortable: true,align:'center'},
			{title:'添加时间', field:'createtime', width:150, sortable:true,align:'center'}
		]]
	});			
});

function query(){
	  $('#datagrid').datagrid('options').queryParams={
	  data:{
	  name:$('#query').find('#name').val(),
	  service_id:$('#query').find('#service_id').val(),
	  type:$('#query').find('#type').val(),
	  info:$('#query').find('#info').val()
	    }
	  }
	  $('#datagrid').datagrid('reload');
	 $('#query').window('close');

}

/*add*/
function close1(){
   $('#add').window('close');
  }
function add(){
    $('#ff').form('submit',{
    url: '{:U('Indicator/insert')}&ajax=true',
    onSubmit:function(){ 
	return $('#ff').form('validate');
	},
    success:function(data){
	var data = runJson(data);
			if(data.status == 0){
				alertText(data.info, 'error');
			}else{
				$.messager.alert('系统提示','新增成功!','info');
				 close1();
		      	$('#datagrid').datagrid('reload');
				
			}
        }
   });
}
/*end add*/
/*edit*/
function close2(){
   $('#edit').window('close');
  }
  
  var indicator_id;
  function getSelect(){
   var select = $('#datagrid').datagrid('getSelected');
   if(select){
    $('#edit').window('open');
    $('#ff').show();
    $('#ff').appendTo('#ee');
	 $('#ff').form('clear');
	 $('#ff').find('#name').val(select.name);
    $('#ff').find('#service_id').val(select.service_id);
    $('#ff').find('#type').val(select.type);
    $('#ff').find('#info').val(select.info);
	$('#ff').find('#indicator_id').val(select.indicator_id);
   }else{
    $.messager.alert('提示','请选择一行数据','warning');
   }
  }
 
 function edit(){
    $('#ff').form('submit',{
	url: '{:U('Indicator/update')}&ajax=true',
    onSubmit:function(){ 
	return $('#ff').form('validate');
	},
    success:function(data){
	var data = runJson(data);
			if(data.status == 0){
				alertText(data.info, 'error');
			}else{
				$.messager.alert('系统提示','修改成功!','info');
				 close2();
		      	$('#datagrid').datagrid('reload');	
			}
        }
   });
}
/*end edit*/
</script>

<script>
		function test(){
			var value = $('#p').progressbar('getValue');
			if (value < 100){
				value += Math.floor(Math.random() * 10);
				$('#p').progressbar('setValue', value);
				setTimeout(arguments.callee, 200);
			}
		}
</script>

<div class="box">
<table id="datagrid"></table>
</div>
 <!--公用-->
  <form id="ff" method="post" style="display:none">
    	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
          <tr>
            <td class="label">指标名称：</td>
            <td>
            <input type="text" id="name" name="name" style="width:200px;" class="easyui-validatebox input" required="true" validType="length[2,20]" />
            </td>
          </tr>
          <tr>
            <td class="label">所属业务：</td>
            <td>
            <select name="service_id" id="service_id" required="true">
            <option value="0">请选择</option>
            <volist name="service" id="type">
            <option value="{$type.value}">{$type.name}</option>
            </volist>
            </select>
             </td>
          </tr>
          <tr>
            <td class="label">指标类型：</td>
            <td>
            <select name="type" id="type" >
            <option value="0">请选择</option>
            <volist name="type_list" id="type">
            <option value="{$type.value}">{$type.name}</option>
            </volist>
            </select>
            </td>
          </tr>
          <tr>
            <td class="label">指标说明：</td>
            <td>
            <textarea class="input" name="info" id="info" style="width:300px; height:50px;">{$vo.info}

</textarea>
            </td>
                <input type="hidden" name="indicator_id"  id="indicator_id"/>
          </tr>
          </table>
          </form>
<!--end-->          
<!--添加-->
  <div id="add" class="easyui-window" title="添加" style="padding: 10px;width:500px;height:250px;" 
iconCls="icon-add" closed="true" maximizable="false" minimizable="false" collapsible="false" resizable="false" modal="true" shadow="true">
     <div id="aa">
     </div>
     <div class="tobutton2">
	 	<a class="easyui-linkbutton" iconCls="icon-add2" href="javascript:void(0)" onclick="add()">新增</a>
         <a class="easyui-linkbutton" iconCls="icon-cancel2" href="javascript:void(0)" onclick="close1()">取消</a>
        </div>
  </div>
<!--end添加-->
<!--edit-->
   <div id="edit" class="easyui-window" title="修改" style="padding: 10px;width:500px;height:250px;"
    iconCls="icon-edit" closed="true" maximizable="false" minimizable="false" collapsible="false" resizable="false" modal="true" shadow="true">
     <div id="ee">
     </div>
      <div class="tobutton2"><a class="easyui-linkbutton" iconCls="icon-add2" href="javascript:void(0)" onclick="edit()">修改</a>
     <a class="easyui-linkbutton" iconCls="icon-cancel2" href="javascript:void(0)" onclick="()">取消</a></div>
    </div>
<!--end_edit-->
<!--query-->
   <div id="query" class="easyui-window" title="查询" style="width: 500px;height:250px;"
    iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false" resizable="false" modal="true" shadow="true">
     <div>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
          <tr>
            <td class="label">指标名称：</td>
            <td>
            <input type="text" value="{$vo.name}" id="name" name="name" style="width:200px;" class="easyui-validatebox input"/>
            </td>
          </tr>
          <tr>
            <td class="label">所属业务：</td>
            <td>
            <select name="service_id" id="service_id" >
            <option value="0">请选择</option>
            <volist name="service" id="type">
            <option value="{$type.value}" <if condition="$type['value'] eq $vo['service_id']">selected</if>>{$type.name}</option>
            </volist>
            </select>
             </td>
          </tr>
          <tr>
            <td class="label">指标类型：</td>
            <td>
            <select name="type" id="type" >
            <option value="0">请选择</option>
            <volist name="type_list" id="type">
            <option value="{$type.value}" <if condition="$type['value'] eq $vo['type']">selected</if>>{$type.name}</option>
            </volist>

            </select>
            </td>
          </tr>
          <tr>
            <td class="label">指标说明：</td>
            <td>
            <textarea class="input" name="info" id="info" style="width:200px;"></textarea>
            </td>
          </tr>
            <tr>
            <td class="label">&nbsp;</td>
            <td><a class="easyui-linkbutton" iconCls="icon-search" href="javascript:void(0);" onclick="query()">查询</a></td>
          </tr>
          </table>
     </div>
    </div>
<!--end-query-->
<include file=".:Common:footer" />